<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台三屏主站控制器
 * 主要获取三屏主站聚合数据
 */
class MainController extends HomeController {

	//三屏主站
    public function index(){
    	$cid = $_SESSION['home']['cid'];
        $main = M('links');
        // $list = D('links')->where('cid='.$cid)->select();
        $count =$main->where(array('cid'=>$cid))->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出
          
          // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list =$main ->order('id')->where(array('cid'=>$cid))->limit($Page->firstRow.','.$Page->listRows)->select();
          // 
          // $this ->assign('cid',$cid);
        $this ->assign('page',$show);
    	$this->assign('list',$list);
        $this->display('Main/index');
    }

    public function edit(){
        $edit = M('links');
        $id = $_GET['id'];
        $list = $edit ->where(array('id'=>$id))->select();

        $this ->assign('list',$list);
        $this->display('Main/edit');
    }


    /*删除*/
    public function delt(){
        $delt = M('links');
        $id = $_POST['id'];
        $res = $delt ->where(array('id' =>$id))->delete();

        if($res){
            $data = array('status'=>true);
            $this ->ajaxReturn($data,'json');
        }else{
            $data = array('status'=>false);
            $this ->ajaxReturn($data,'json');
        }
    }


    public function editAc(){
        $editAc = M('links');

        $id = $_POST['id'];

        $editAc ->create();
        $res = $editAc ->where(array('id'=>$id))->save();

        if ($res) {
            $this ->redirect('Main/index');
        }else{
            $this ->error();
        }


    }


    public function map(){
        $map = M('map');
        $cid = $_SESSION['home']['cid'];

        $list = $map ->where(array('cid'=>$cid)) ->select();
        $this ->assign('list',$list);
        $this ->display('Main/map');
    }


    public function mapadd(){
   
        $cid = $_SESSION['home']['cid'];
    	$_POST['cid'] = $cid;

		$map = M('map');
        $map ->create();
    	$result = $map->add();

	    if($result){
	   		$this->display('Mainsite/map');
    	}else{
    		$this->error('新增失败!');
    	}
    }

    public function links(){

        $this->display();
    }

    public function linksadd(){
    	
      
        $cid = $_SESSION['home']['cid'];
        $_POST['cid'] = $cid;
        // print_r($data);
        // exit;
        
        $links = D('links');
        $links ->create();
        $res = $links->add();
    
	    if($res){
	   		$this->redirect('Main/index');
    	}else{
    		$this->error();
    	}

    }

}